#include <gflags/gflags.h>
#include <thread>
#include "../../../common/data_redis.hpp"

DEFINE_string(server_ip, "127.0.0.1", "这是服务器的监听地址，格式为[0.0.0.0]");
DEFINE_int32(server_port, 6379, "这是redis服务器的监听端口，格式为[6379]");
DEFINE_bool(keep_alive, true, "是否启用长连接保活，格式为[true/false]");
DEFINE_int32(db, 0, "库的编号，默认为0");

DEFINE_bool(log_mode, false, "程序的运行模式: true-发布模式 false-调试模式");
DEFINE_string(log_file, "", "发布模式下，制定日志的输出文件");
DEFINE_int32(log_level, 0, "发布模式下，制定日志的输出等级");

void Session_test(const bite_im::RedisPtr &client)
{
    bite_im::Session session(client);
    session.append("会话1", "2022044026");
    session.append("会话2", "2024044026");

    session.remove("会话2");

    auto res = session.uid("会话1");
    if (res)
    {
        std::cout << *res << std::endl;
    }
    res = session.uid("会话2");
    if (res)
    {
        std::cout << *res << std::endl;
    }
}
void Status_test(const bite_im::RedisPtr &client)
{
    bite_im::Status status(client);
    status.append("test1");
    std::cout << status.exists("test1") << std::endl;
    std::cout << status.exists("会话1") << std::endl;
    std::cout << status.exists("会话2") << std::endl;
}
void Codes_test(const bite_im::RedisPtr &client)
{
    bite_im::Codes coder(client);
    coder.append("验证码1", "432248", 5);
    auto res = coder.code("验证码1");
    if (res)
    {
        std::cout << *coder.code("验证码1") << std::endl;
    }
    std::this_thread::sleep_for(std::chrono::seconds(6));
    res = coder.code("验证码1");
    if (res)
    {
        std::cout << *coder.code("验证码1") << std::endl;
        std::cout << "没输出代表此时res为空了" << std::endl;
    }
}

int main(int argc, char *argv[])
{
    google::ParseCommandLineFlags(&argc, &argv, true);
    // initLogger(FLAGS_log_mode, FLAGS_log_file, FLAGS_log_level);
    auto client = bite_im::RedisFactory::create(FLAGS_server_ip, FLAGS_server_port, FLAGS_keep_alive, FLAGS_db);
    // Session_test(client);
    // Status_test(client);
    // Codes_test(client);
}